package com.carleasoft.mps.cms.business.education.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.business.education.bean.entity.EducationCollectEntity;
import com.carleasoft.mps.cms.business.education.bean.po.EducationPageQueryPo;
import com.carleasoft.mps.cms.business.education.bean.po.EducationPo;
import com.carleasoft.mps.cms.business.education.bean.po.EducationCodePo;
import com.carleasoft.mps.cms.business.education.bean.vo.*;
import com.carleasoft.mps.cms.business.education.service.EduCollectService;
import com.carleasoft.mps.cms.business.education.service.EduDoorService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 教育分类库
 *
 * @author: yangHao
 * @createDate:2023/5/18
 * @description:
 */
@RestController
@RequestMapping("/eduCollect")
public class EduCollectController {

    @Autowired
    private EduDoorService eduDoorService;
    @Autowired
    private EduCollectService eduCollectService;

    /**
     * 教学资源八库-分页
     *
     * @param educationPageQueryPo
     * @param request
     * @return
     */
    @PostMapping("/pageQuery")
    public R pageQuery(@RequestBody EducationPageQueryPo educationPageQueryPo, HttpServletRequest request) {
        Page<EduPageQueryVo> eduPageQueryVoPage = eduDoorService.pageQuery(new Page(educationPageQueryPo.getCurrent(), educationPageQueryPo.getSize()), educationPageQueryPo, request);
        return R.ok(eduPageQueryVoPage);
    }


    /**
     * 教学资源八库-新增
     *
     * @param educationPo
     * @param request
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody EducationPo educationPo, HttpServletRequest request) {
        boolean isOk = eduDoorService.saveResource(educationPo, request);
        return R.ok(isOk);
    }

    /**
     * 教学资源八库-编辑
     *
     * @param educationPo
     * @param request
     * @return
     */
    @PostMapping("/update")
    public R update(@RequestBody EducationPo educationPo, HttpServletRequest request) {
        IBeanUtil.paramVerify(educationPo, "eduResourceCode");
        boolean isOk = eduDoorService.updateResource(educationPo, request);
        return R.ok(isOk);
    }


    /**
     * 教学资源八库-置顶
     *
     * @param educationPo
     * @return
     */
    @PostMapping("/top")
    public R top(@RequestBody EducationPo educationPo) {
        IBeanUtil.paramVerify(educationPo, "eduResourceCode", "topType");
        boolean isOk = eduDoorService.top(educationPo);
        return R.ok(isOk);
    }

    /**
     * 教学资源八库-删除
     *
     * @param educationPo
     * @return
     */
    @PostMapping("/delete")
    public R delete(@RequestBody EducationPo educationPo) {
        IBeanUtil.paramVerify(educationPo, "eduResourceCode");
        boolean isOk = eduDoorService.delete(educationPo);
        return R.ok(isOk);
    }

    /**
     * 教学资源八库-详情
     *
     * @param educationPo
     * @return
     */
    @PostMapping("/detail")
    public R detail(@RequestBody EducationPo educationPo) {
        IBeanUtil.paramVerify(educationPo, "eduResourceCode");
        EducationCollectVo educationCollectVo = eduDoorService.detail(educationPo);
        return R.ok(educationCollectVo);
    }

    /**
     * 教学资源八库-新增分类
     *
     * @param educationCollectEntity
     * @param request
     * @return
     */
    @PostMapping("/saveCategory")
    public R saveCategory(@RequestBody EducationCollectEntity educationCollectEntity, HttpServletRequest request) {
        boolean isOk = eduCollectService.saveCategory(educationCollectEntity, request);
        return R.ok(isOk);
    }

    /**
     * 教学资源八库-幂等检测 查询分类是否名字重复
     *
     * @param educationCollectEntity
     * @return
     */
    @PostMapping("/check")
    public R check(@RequestBody EducationCollectEntity educationCollectEntity) {
        IBeanUtil.paramVerify(educationCollectEntity, "categoryName", "education");
        boolean isOk = eduCollectService.check(educationCollectEntity);
        return R.ok(isOk);
    }

    /**
     * 教学资源八库-删除
     *
     * @param educationCollectEntity
     * @return
     */
    @PostMapping("/deleteCategory")
    public R deleteCategory(@RequestBody EducationCollectEntity educationCollectEntity) {
        IBeanUtil.paramVerify(educationCollectEntity, "categoryCode");
        boolean isOk = eduCollectService.deleteCategory(educationCollectEntity);
        return R.ok(isOk);
    }


    /**
     * 教学资源八库-分类列表
     *
     * @return
     */
    @PostMapping("/categoryList")
    public R categoryList() {
        List<EducationCollectEntity> reasourceCollectEntities = eduCollectService.categoryList();
        return R.ok(reasourceCollectEntities);
    }


    /**
     * 根据所属库查询分类数据
     *
     * @return
     */
    @PostMapping("/getEducationByCategory")
    public R getEducationByCategory(@RequestBody EducationPo educationPo) {
        IBeanUtil.paramVerify(educationPo, "education");
        List<EduCategoryVo> eduCategoryVos = eduDoorService.getEducationByCategory(educationPo);
        return R.ok(eduCategoryVos);
    }

    /**
     * 门户 收藏/取消收藏/浏览/下载
     *
     * @param educationPo
     * @return
     */
    @PostMapping("/viewDetail")
    public R viewDetail(@RequestBody EducationPo educationPo, HttpServletRequest request) {
        IBeanUtil.paramVerify(educationPo, "eduResourceCode", "openType");
        boolean isOk = eduDoorService.viewDetail(educationPo, request);
        return R.ok(isOk);
    }

    /**
     * 资源概况
     *
     * @return
     */
    @PostMapping("/workbenchCount")
    public R workbenchCount() {
        EduWorkCountVo eduWorkCountVo = eduDoorService.workbenchCount();
        return R.ok(eduWorkCountVo);
    }


    /**
     * web-教学资源概况
     * @return
     */
    @PostMapping("/webCount")
    public R webCount() {
        List<EduCountVo> eduCountVos = eduDoorService.webCount();
        return R.ok(eduCountVos);
    }


    /**
     * 导出资源八库
     * @param
     * @return
     */
    @PostMapping("/importExcel")
    public R importExcel(@RequestBody EducationCodePo educationCodePo, HttpServletResponse response){
      boolean isOk=  eduDoorService.importExcel(educationCodePo,response);
      return R.ok(isOk);
    }

}
